package com.consumer.handsome.controller;

import com.consumer.handsome.domain.dto.*;
import com.consumer.handsome.response.BaseResponse;
import com.consumer.handsome.utils.HttpClientUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;

/**
 * @Author yisen
 * @Date 2024/5/11 12:33
 * @PackageName:com.consumer.handsome.controller
 * @ClassName: BusController
 * @Description: TODO
 * @Version 1.0
 */
@RestController
@RequestMapping("/bus")
@Api(tags = "公交车操作")
@Slf4j
public class BusController {
    @Value("${bus.uname}")
    public String uname;
    @Value("${bus.key}")
    public String key;
    @Value("${bus.url}")
    public String url;

    @ApiOperation(value = "公交路线")
    @PostMapping("/busLuXian")
    public BaseResponse getLuXian(@RequestBody LuXianSearchDTO luXianSearchDTO){
        HttpClientUtil httpClientUtil = new HttpClientUtil();
        String md = uname+key+"luxian";
        String keySecret = DigestUtils.md5DigestAsHex(md.getBytes());
        LuXianDTO luXianDTO = new LuXianDTO();
        luXianDTO.setOptype("luxian");
        luXianDTO.setUname(uname);
        luXianDTO.setCityid(luXianSearchDTO.getCityid());
        luXianDTO.setKeySecret(keySecret);
        luXianDTO.setKeywords(luXianSearchDTO.getKeywords());
        String s = httpClientUtil.GetResponse(url, luXianDTO);
        return new BaseResponse(s);
    }
    @ApiOperation(value = "公交实时位置")
    @PostMapping ("/bus")
    public BaseResponse getBusPosition(@RequestBody PositionLuXianDTO positionLuXianDTO){
        HttpClientUtil httpClientUtil = new HttpClientUtil();
        String md = uname+key+"rtbus";
        String keySecret = DigestUtils.md5DigestAsHex(md.getBytes());
        PositionLuXianxDTO positionLuXianxDTO = new PositionLuXianxDTO();
        positionLuXianxDTO.setOptype("rtbus");
        positionLuXianxDTO.setUname(uname);
        positionLuXianxDTO.setCityid(positionLuXianDTO.getCityid());
        positionLuXianxDTO.setBus_linestrid(positionLuXianDTO.getBus_linestrid());
        positionLuXianxDTO.setBus_linenum(positionLuXianDTO.getBus_linenum());
        positionLuXianxDTO.setBus_staname(positionLuXianDTO.getBus_staname());
        positionLuXianxDTO.setKeySecret(keySecret);
        String s = httpClientUtil.GetResponse(url, positionLuXianxDTO);
        return new BaseResponse(s);
    }
    @ApiOperation(value = "获取指定地址标识")
    @PostMapping ("/bus/imlgn")
    public BaseResponse getImlgn(@RequestBody BusImlgnDTO busImlgnDTO){
        HttpClientUtil httpClientUtil = new HttpClientUtil();
        String md = uname+key+"tfrone";
        String keySecret = DigestUtils.md5DigestAsHex(md.getBytes());
        BusImlgnXDTO busImlgnXDTO = new BusImlgnXDTO();
        busImlgnXDTO.setOptype("tfrone");
        busImlgnXDTO.setUname(uname);
        busImlgnXDTO.setCityname(busImlgnDTO.getCityname());
        busImlgnXDTO.setKeywords(busImlgnDTO.getKeywords());
        busImlgnXDTO.setKeySecret(keySecret);
        String s = httpClientUtil.GetResponse(url, busImlgnXDTO);
        return new BaseResponse(s);
    }
    @ApiOperation(value = "获取路线规划")
    @PostMapping ("/bus/root")
    public BaseResponse getRoot(@RequestBody BusRootDTO busRootDTO){
        HttpClientUtil httpClientUtil = new HttpClientUtil();
        String md = uname+key+"tfrtwo";
        String keySecret = DigestUtils.md5DigestAsHex(md.getBytes());
        BusRootxDTO busRootxDTO = new BusRootxDTO();
        busRootxDTO.setOptype("tfrtwo");
        busRootxDTO.setUname(uname);
        busRootxDTO.setStasta(busRootDTO.getStasta());
        busRootxDTO.setStaimlgn(busRootDTO.getStaimlgn());
        busRootxDTO.setEndsta(busRootDTO.getEndsta());
        busRootxDTO.setEndimlgn(busRootDTO.getEndimlgn());
        busRootxDTO.setKeySecret(keySecret);
        String s = httpClientUtil.GetResponse(url, busRootxDTO);
        return new BaseResponse(s);
    }



}
